package mysql

import "gorm.io/gorm"

type User1 struct {
	gorm.Model
	Name string `gorm:"type:varchar(10);comment:用户名"`
	Tel  string `gorm:"type:char(11);comment:手机号"`
}

type Goods1 struct {
	gorm.Model
	GoodsName  string  `gorm:"type:varchar(10);comment:商品名称"`
	GoodsPrice float64 `gorm:"type:decimal(10,2);comment:商品价格"`
	GoodsNum   int     `gorm:"type:int(10);comment:商品库存"`
	GoodsImg   string  `gorm:"type:varchar(255);comment:商品封面"`
	LikeCount  int     `gorm:"type:int(10);comment:商品收藏数量"`
	GoodsType  int     `gorm:"type:int(1);comment:商品类别:0-水果，1-电器，2-家具"`
}

type Order1 struct {
	gorm.Model
	UserId      int     `gorm:"type:int(10);comment:用户id"`
	GoodsId     int     `gorm:"type:int(10);comment:商品id"`
	OrderSn     string  `gorm:"type:char(36);comment:订单号"`
	OrderStatus int     `gorm:"type:int(1);comment:订单状态:0-已支付，1-未支付"`
	PayType     int     `gorm:"type:int(1);comment:支付方式:0-微信，1-支付宝"`
	Amount      float64 `gorm:"type:decimal(10,2);comment:订单金额"`
	GoodsName   string  `gorm:"type:varchar(20);comment:商品名称"`
	GoodsImg    string  `gorm:"type:varchar(255);comment:商品封面"`
}

func (g *Goods1) RankType(GoodsType int) error {
	return DB.Where("goods_type=?", GoodsType).Find(&g).Error
}

func (o *Order1) Update(OrderSn string, Status string) error {
	return DB.Model(&o).Where("order_sn=?", OrderSn).Update("status", Status).Error
}
